home *** CD-ROM | disk | FTP | other *** search
- // heari3: see if korg is responding
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <ctype.h>
- #include <time.h>
- #include "sb.hpp"
- #include "mpu.hpp"
- #include <stdlib.h>
-
- Soundcard* card = 0;
- int copy = 0;
- int dump = 1;
-
- unsigned char mapchannel[16] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
- };
-
- unsigned char ignorelow[16] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- };
-
- #define ISLOW(note) (note <= 0x36)
-
- int hear()
- {
- card->reset();
- unsigned char c;
- int ret = 0;
- int col = 0;
- unsigned char checklow = 0;
-
- fprintf(stderr, "send midi commands from external keyboard:\n");
- card->startinput();
- while (1)
- {
- int count = card->hear(&c, 1);
- if (count <= 0)
- {
- if (kbhit() && getch() == 27)
- break;
- continue;
- }
- ret = 1;
- if (c == 0xFE)
- {
- if (kbhit() && getch() == 27)
- break;
- if (dump)
- {
- putchar('°');
- col++;
- }
- }
- else if (c == 0xF8)
- {
- if (kbhit() && getch() == 27)
- break;
- if (dump)
- {
- putchar('.'); // tick
- col++;
- }
- }
- else
- {
- if (copy)
- {
- if (checklow)
- {
- if (ISLOW(c))
- {
- checklow = (checklow & 15) + 0x80; // note off
- c = 0;
- }
- card->play(&checklow, 1);
- }
- checklow = 0;
- if (c & 0x80 && c < 0xF0)
- {
- int ch = c & 15;
- if (mapchannel[ch] != c)
- {
- c = (c & 0xF0) + mapchannel[ch];
- ch = c & 15;
- }
- if ((c & 0x80) <= 0x90 && ignorelow[ch])
- {
- checklow = c;
- }
- }
- card->play(&c, 1);
- }
- if (dump)
- {
- if (c & 0x80)
- {
- if (dump)
- putchar('\n');
- col = 0;
- }
- else
- {
- if (dump)
- putchar(' ');
- col++;
- }
- printf("%02X", c);
- col += 2;
- }
- }
- if (dump && col >= 75)
- {
- putchar('\n');
- col = 0;
- }
- }
- card->stopinput();
- return ret;
- }
-
-
- int main(int argc, char** argv)
- {
- argc--; argv++;
- while (argc > 0 && **argv == '-')
- {
- if (strnicmp(*argv, "-help", 2) == 0)
- {
- fprintf(stderr, "usage: heari3 [-copy] [-nodump] [-drum #]\n");
- return 1;
- }
- if (strnicmp(*argv, "-copy", 2) == 0)
- {
- copy = 1;
- argc--; argv++; continue;
- }
- if (strnicmp(*argv, "-drum", 2) == 0)
- {
- argc--; argv++;
- if (argc > 0)
- {
- int ch = atoi(*argv); argc--; argv++;
- if (ch >= 1 && ch <= 16)
- mapchannel[ch-1] = 9;
- }
- continue;
- }
- if (strnicmp(*argv, "-nodump", 2) == 0)
- {
- dump = 0;
- argc--; argv++; continue;
- }
- if (strnicmp(*argv, "-ignorelow", 2) == 0)
- {
- argc--; argv++;
- if (argc > 0)
- {
- int ch = atoi(*argv); argc--; argv++;
- if (ch >= 1 && ch <= 16)
- ignorelow[ch-1] = 1;
- }
- continue;
- }
- fprintf(stderr, "invalid option %s\n", *argv);
- argc--; argv++;
- }
- card = detect_soundcard();
- if (!card)
- {
- fprintf(stderr, "Could not detect soundcard\n");
- return 1;
- }
-
- if (!hear())
- fprintf(stderr, "no response from soundcard\n");
-
- delete card;
- return 0;
- }
-